﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;

namespace Salon
{
    class SqlService
    {
        private SqlService()
        { }


        private static SqlService service = null;

        SqlConnection conn = null;

        //namiary na bazę są przechowywane w pliku app.config
        String connString = ConfigurationSettings.AppSettings["ConnectionString"];


        public static SqlService getInstance()
        {
            if (service == null)
                service = new SqlService();

            return service;
        }

        public SqlConnection getConnection()
        {
            if (conn == null)
                conn = new SqlConnection(connString);

            if (conn.State == System.Data.ConnectionState.Closed)
                conn.Open();

            return conn;
        }

        /// <summary>
        /// Zwraca obiekt SqlCommand z instrukcją podaną w argumencie
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public SqlCommand getCommand(String query)
        {
            getConnection();
            return new SqlCommand(query, conn);
        }
    }
}
